<script setup lang="ts">
import {message, Modal} from "ant-design-vue";
import {WxtBizCode, WxtUtils} from "~/contentScripts/views/wxt/lib/wxtUtils";

const title = '批量删除人群';
const props = defineProps({
  crowds: {
    type: Array,
    default: () => [],
  },
  bizCode: {
    type: String as PropType<WxtBizCode>,
    default: WxtBizCode.关键字推广,
  },
});
const emit = defineEmits(['refresh']);
const handle = () => {
  if (props.crowds.length === 0) {
    message.error('请勾选需要删除的人群!');
    return;
  }
  Modal.confirm({
    title: '人群删除',
    content: '确认删除选中的人群信息，一旦删除不可恢复!',
    onOk: () => {
      WxtUtils.customRequest('https://one.alimama.com/crowd/batchDelete.json', props.bizCode,{
        crowdList: props.crowds.map((c: any) => {
          return {
            adgroupId: c.adgroupId,
            campaignId: c.campaignId,
            crowd: {
              crowdId: c.crowdId,
            },
            crowdId: c.crowdId,
          }
        }),
      }).then(() => {
        message.success('删除成功!');
        emit('refresh');
      });
    },
  });
}
</script>

<template>
<div @click="handle">
  <slot>
    <a-button type="primary" ghost danger size="small">批量删除</a-button>
  </slot>
</div>
</template>

<style scoped>

</style>
